package com.ella.controller;


import com.ella.entity.Result;
import com.ella.entity.SysMenu;
import com.ella.service.ISysMenuService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sys-index")
public class SysIndexController {

  @Resource
  private ISysMenuService sysMenuService;

	/**
	 * 这个角色的默认字符串未ROLE_为前缀 ，你在封装角色时需要将前缀给拼接上，至于hasRole('admin')里面你带不带前缀都行
	 *
	 * */
	@PostMapping("/getRouters")
	@PreAuthorize("hasRole('admin')")
	public Result getRouters(){
		List<SysMenu> menus = sysMenuService.selectMenuTrees();
		return Result.ok().put("data",menus);
	}

	@PostMapping("/testROLE")
	@PreAuthorize("hasRole('ROLE_admin')")
	public Result testRole(){
		return Result.ok("验证成功");
	}

}
